package com.xique.system.api.factory;


import com.xique.common.core.domain.R;
import com.xique.system.api.RemoteSystemProjectService;
import com.xique.system.api.dto.SystemProjectDTO;
import com.xique.system.api.request.RemoteSystemProjectAllListRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 日志服务降级处理
 *
 * @author xique
 */
@Component
public class RemoteSystemProjectFallbackFactory implements FallbackFactory<RemoteSystemProjectService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemProjectFallbackFactory.class);

    @Override
    public RemoteSystemProjectService create(Throwable throwable) {
        log.error("服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemProjectService() {

            @Override
            public R<SystemProjectDTO> getProjectInfo(Long parkId) {
                return R.fail("获取项目信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SystemProjectDTO>> getProjectList(RemoteSystemProjectAllListRequest request) {
                return R.fail("获取项目列表信息失败:" + throwable.getMessage());
            }
        };
    }

}
